<?php
class Model_member extends CI_Model {
	 function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
    
	/*function quickreg(){
		$email = $this->input->post('email');	
		$this->username = $this->input->post('username');
	    $this->password = $this->passwordCreation();
		$insArr  = array( "username" => $this->username,
						   "password"  => $this->password,
						    "status" => 1,
							"deleted"=>0,
							"user_type" =>2,
							"email" => $email,
							"quickreg" => 1);
		$query = $this->db->insert("m_members",$insArr);
		
	}*/
	function registration(){
		$time 		= time();
		$createdby  = $this->input->post('profile');
		$fname 		= $this->input->post('fname');
		$dname 		= $this->input->post('lname');
		$gender 	= $this->input->post('gender');
		$unique_id  = uniqueid();
		$dobM 		= $this->input->post('month');
		$dobD 		= $this->input->post('day');
		$dobY 		= $this->input->post('year');	
		$dob 		= mktime(0,0,0,$dobM,$dobD,$dobY);
		
		$maritalStatus     = $this->input->post("maritalStatus");
		$religion	       = $this->input->post("religion");
		$denomination      = $this->input->post("denomination");
		$cast	       	   = $this->input->post("cast");
		$living_country	   = $this->input->post("living_country");
		$mob_countrycode   = $this->input->post("mob_countrycode");
		$mob_phone	       = $this->input->post("mob_phone");
		$email	           = $this->input->post("email");
		$password	       = $this->input->post("password");
		
		$heightFeet = $this->input->post("heightFeet");
		$physicalStatus= $this->input->post("physicalStatus");
		
		$education= $this->input->post("education");
		$occupation= $this->input->post("occupation");
		

		$insArr  = array( "createdby" => $createdby,
						   "fname"  => $fname,
						    "unique_id"  => $unique_id,
						   
						    "gender" => $gender,
							"displayname"=> $dname,
    						"dob" => $dob,
							"maritalstatusid" => $maritalStatus,
							"religion" => $religion,
							"denomination"=> $denomination,
							"cast"=> $cast,
							"living_country"=> $living_country,
							"mob_countrycode"=> $mob_countrycode,
							"mob_phone"=> $mob_phone,
							"email"=> $email,
							"password"=> $password,
							"status"=>1,
							"height" => $heightFeet,
							"physical_status" => $physicalStatus,
							"education" => $education,
							"occupation" => $occupation
							);
							
		 $this->db->insert("m_members",$insArr);
		 $members_id = $this->db->insert_id();
		 $insArr_family  = array( "members_id" => $members_id);
		 $this->db->insert("m_family",$insArr_family);	
	}
	function update_basicinformation(){
	
		$createdby 		= $this->input->post("createdby");
		$fname		    = $this->input->post("fname");
		$lname 			= $this->input->post("lname");
		$weight 		= $this->input->post("weightKgs");
		$heightFeet     = $this->input->post("heightFeet");
		
		$dobM 		= $this->input->post('month');
		$dobD 		= $this->input->post('day');
		$dobY 		= $this->input->post('year');	
		$dob 		= mktime(0,0,0,$dobM,$dobD,$dobY);
		
		$body_type		= $this->input->post("body_type");
		$complexion		= $this->input->post("complexion");
		$physical_status		= $this->input->post("physical_status");
		
		$eating_habits		= $this->input->post("eating_habits");		
		$smoking_habits		= $this->input->post("smoking_habits");
		$drinking_habits	= $this->input->post("drinking_habits");
	
		$occupation = $this->input->post("occupation");
		$occupation_details = $this->input->post("occupation_details");
		$employed_in = $this->input->post("employed_in");
		$income_type = $this->input->post("income_type");
		$income = $this->input->post("income");
		if(count($this->input->post("languages_known")>0)){
			$languages_known   = $this->input->post("languages_known");
			$languages_known=implode(",",$languages_known);
		}
		
		$aboutme			= $this->input->post("aboutme");		
		$insArr  = array( "createdby" => $createdby,
							"fname" => $fname,
							"lname" => $lname,
							"languages_known" => $languages_known,
							"height" => $heightFeet,
							"weight" => $weight,
							"body_type" => $body_type,
							"dob" => $dob,
						    "complexion" => $complexion,
							"physical_status" => $physical_status,
							"eating_habits" => $eating_habits,
							"smoking_habits" => $smoking_habits,
							"drinking_habits" => $drinking_habits,
							"occupation" => $occupation,
							"occupation_details"=> $occupation_details,
    						"employed_in" => $employed_in,
							"income_type" => $income_type,
							"income" => $income,
							"aboutme" => $aboutme
							);
		$this->db->update('m_members', $insArr, array('id' => $this->session->userdata("USER_ID")));
	
	
	}
	function update_location(){
		$living_country 		= $this->input->post("living_country");
		$living_state		    = $this->input->post("living_state");
		$city 			= $this->input->post("city");
		$citizenship 		= $this->input->post("citizenship");
		$insArr  = array( "living_country" => $living_country,
							"living_state" => $living_state,
							"city" => $city,
							"citizenship" => $citizenship
							);
		$this->db->update('m_members', $insArr, array('id' => $this->session->userdata("USER_ID")));
	
	}
	function update_educationdetails(){
		$education = $this->input->post("education");
		$education_details = $this->input->post("education_details");
		$occupation = $this->input->post("occupation");
		$occupation_details = $this->input->post("occupation_details");
		$employed_in = $this->input->post("employed_in");
		$income_type = $this->input->post("income_type");
		$income = $this->input->post("income");
		$insArr  = array( "education" => $education,
						   "education_details"  => $education_details,
						    "occupation" => $occupation,
							"occupation_details"=> $occupation_details,
    						"employed_in" => $employed_in,
							"income_type" => $income_type,
							"income" => $income
							);
	//	$this->db->update('fc_classifids', $insArr,array("id"=>$id));					
		$this->db->update('m_members', $insArr, array('id' => $this->session->userdata("USER_ID")));
	
	}
	function update_family_details(){
		$family_contact_number = $this->input->post("family_contact_number");
		$family_value		   = $this->input->post("family_value");
		$family_type		   = $this->input->post("family_type");
		$family_status = $this->input->post("family_status");
		$family_orgin = $this->input->post("family_orgin");
		$religious_value = $this->input->post("religious_value");
		$fathers_occupation = $this->input->post("fathers_occupation");
		$mothers_occupation = $this->input->post("mothers_occupation");
		$fathers_name = $this->input->post("fathers_name");
		$fathers_nativeplace = $this->input->post("fathers_nativeplace");
		$mothers_name = $this->input->post("mothers_name");
		$mothers_nativeplace = $this->input->post("mothers_nativeplace");
		$no_brothers = $this->input->post("no_brothers");
		$no_brothers_married = $this->input->post("no_brothers_married");	
		$no_sisters = $this->input->post("no_sisters");	
		$no_sisters_married = $this->input->post("no_sisters_married");	
		$fathers_housename = $this->input->post("fathers_housename");
		$mothers_housename = $this->input->post("mothers_housename");
		$about_family = $this->input->post("about_family");
		$insArr  = array( "family_contact_number" => $family_contact_number,
						  "family_value" => $family_value,
						  "family_type" => $family_type,
						  "family_status" => $family_status,
						  "family_orgin" => $family_orgin,
						  "religious_value" => $religious_value,
						  "fathers_occupation" => $fathers_occupation,
						  "mothers_occupation" => $mothers_occupation,
						  "fathers_name" => $fathers_name,						  
						  "fathers_nativeplace" => $fathers_nativeplace,
						  "mothers_name" => $mothers_name,
						  "mothers_nativeplace" => $mothers_nativeplace,
						  "no_brothers" => $no_brothers,
						  "no_brothers_married" => $no_brothers_married,
						  "no_sisters" => $no_sisters,
						  "no_sisters_married" => $no_sisters_married,
						  "fathers_housename" => $fathers_housename,
						  "mothers_housename" => $mothers_housename,
						  "about_family" => $about_family);
		$this->db->update('m_family', $insArr, array('members_id' => $this->session->userdata("USER_ID")));
		}
	function update_partner_preference(){
		
		    $marital_status = serialize($this->input->post("marital_status"));
			$have_children = $this->input->post("have_children");
			$age_from = $this->input->post("age_from");
			$age_to = $this->input->post("age_to");
			$height_from = $this->input->post("height_from");
			$height_to	 = $this->input->post("height_to");
			$physical_status = $this->input->post("physical_status");
			$denomination	 = $this->input->post("denomination	");
			$education = $this->input->post("education");
			$occupation = $this->input->post("occupation");
			$citizen = $this->input->post("citizen");
			$county_living = $this->input->post("county_living");
			$residing_state = $this->input->post("residing_state");
			$food_habit = $this->input->post("food_habit");
			$smoking_habit = $this->input->post("smoking_habit");
			$drinking_habit = $this->input->post("drinking_habit");
			$annual_income = $this->input->post("annual_income");
			$about_partner  = $this->input->post("about_partner");
			
			
			 $insArr  = array("marital_status" => $marital_status,
							  "have_children" => $have_children,
							  "citizen" => $citizen,
							  "age_from" => $age_from,						  
							  "age_to" => $age_to,
							  "height_from" => $height_from,
							  "height_to" => $height_to,
							  "physical_status" => $physical_status,
							  "denomination" => $denomination,
							  "education" => $education,
							  "occupation" => $occupation,
							  "citizen" => $citizen,
							  "county_living" => $county_living,
							  "residing_state" => $residing_state,
							  "food_habit" => $food_habit,
							  "smoking_habit" => $smoking_habit,
							  "drinking_habit" => $drinking_habit,
							  "annual_income" => $annual_income,
							  "about_partner" => $about_partner);
			 
		$this->db->update('m_partner_preference', $insArr, array('member_id' => $this->session->userdata("USER_ID")));
	}
		
	
	function upoladimages($orig_name){
	
		$member_id = $this->session->userdata("USER_ID");
		
		
		$insArr  = array( "member_id" => $member_id,
						   "status"  => 0,
						   "name"=> $orig_name,
						    "sort_order" => 1
							
							);
		$query = $this->db->insert("m_photos",$insArr);
	
	}
	function getAllImages(){
	$this->query = $this->db->query("SELECT m_photos.* FROM m_photos WHERE member_id =".$this->session->userdata("USER_ID")."");
	$this->num_rows = $this->query->num_rows();
	}
	function getProfilePicture(){
		$this->db->select('*');
		$this->db->from('m_photos');
		$this->db->where("member_id" ,$this->session->userdata("USER_ID"));
		$this->db->where("profile_picture", 1);		
		$query = $this->db->get();
		$row = $query->result();
		return (isset($row[0]->name)) ? $row[0]->name : '';

	}
	function getAmember($memid){
		$this->db->where("id" ,$memid);
		$query = $this->db->get("m_members");
		if ($query->num_rows() > 0){
			$row = $query->result(); 
			$this->memberDetails = $row[0];			
		}
	}
	function getAmember_family($members_id){
		$this->db->where("members_id" ,$members_id);
		$query = $this->db->get("m_family");
		if ($query->num_rows() > 0){
			$row = $query->result(); 
			$this->memberDetailsFamily = $row[0];			
		}
	}
	function get_partner_preference($members_id){
		$this->db->where("member_id	" ,$members_id);
		$query = $this->db->get("m_partner_preference");
		if ($query->num_rows() > 0){
			$row = $query->result(); 
			$this->memberPreferences = $row[0];			
		}
	}
	function getAllm_actcreatedby(){
		$this->db->select("m_actcreatedby.*");
		$this->db->from("m_actcreatedby");		
		
		$this->db->order_by("sortorder", "ASC");
		$this->queries  = $this->db->get();
	}
	
	function getAllm_maritalstatus(){
		$this->db->select("m_maritalstatus.*");
		$this->db->from("m_maritalstatus");
	
		$this->db->order_by("sortorder", "ASC");
		$this->queries  = $this->db->get();
	}
	
	function emailExists($email){
		$this->db->select("COUNT(id) AS mem_cnt");
		$this->db->from("m_members");
		$this->db->where("email" ,$email);		
		$query  = $this->db->get();
		$row = $query->result(); 
		return $row[0]->mem_cnt;
	}
	
	function user_login($email,$password){
		
		$email = $this->security->xss_clean($email);
		$password = $this->security->xss_clean($password);
		
		$this->db->select("*");
		$this->db->where("email" ,$email);
		$this->db->where("password" ,$password);						
		$this->db->from("m_members");
		
		
		$query  = $this->db->get();
				
		if ($query->num_rows() > 0){
			$row = $query->result();
			$this->memberDetails = $row[0];			
			return true;
		}else{
			return false;
		}
	}
	
	function search(){
		$this->query = $this->db->query("SELECT m_members.* FROM m_members");
		$this->num_rows = $this->query->num_rows();
	}
	function searchAll($limit, $start) {
		$this->db->limit($limit,$start);
		$this->query = $this->db->get("m_members");
		$this->num_rows = $this->query->num_rows();
	}
	function getAllMembers($status=0){
		$this->db->select("*");
		$this->db->from("m_members");		
		$this->db->where("status" ,$status);					
		$this->queries  = $this->db->get();
		
		}
	
	/*function update_myaccount(){
		$insArr  = array("fname" => $this->input->post('firstname'),
						  "mname" => $this->input->post('middlename'),
						  "lname" => $this->input->post('lastnameval')  );
		$this->db->where("id",$this->session->userdata('SESS_ID'));
		$query = $this->db->update("m_members",$insArr);
	}
	
	function changepassword(){
			$oldpass = $this->input->post('oldpass');	
			$newpass = $this->input->post('newpass');	
			$insArr  = array("password" => $this->input->post('newpass'));
			$this->db->where("id",$this->session->userdata('SESS_ID'));
			$query = $this->db->update("m_members",$insArr);			
	}
	
	
	
	function forgot_pass(){
		$this->db->where(array("username" => $this->input->post('username') , 
								"status" => 1 , 
								"deleted" => 0));
		$query = $this->db->get("m_members");		
		if ($query->num_rows() > 0){
		   foreach ($query->result() as $row){
			  $this->memid =  $row->id;
			  $this->username = $row->username;
			  $this->password = $row->password;
			  $this->status=  $row->status;			  
			  $this->user_type=  $row->user_type;		
			  $this->fname=  $row->fname;			  	  			  
			  $this->email=  $row->email;			  	  			  			  
		   }
		  return true;
		}else{
			return false;
		}
	}
	
	function admin_login($usertype='2'){
		$this->db->where(array("username" => $this->input->post('username') , 
								"password" => $this->input->post('password') ,
								 "status" =>1 , 
								 "deleted" => 0, 
								 "user_type" => $usertype ));
		$query = $this->db->get("m_admin");
		if ($query->num_rows() > 0){
		   foreach ($query->result() as $row){
			  $this->memid =  $row->id;
			  $this->username = $row->username;
			  $this->password = $row->password;
			  $this->status=  $row->status;			  
			  $this->user_type=  $row->user_type;		
			  $this->fname=  $row->fname;			  	  			  
			  $this->email=  $row->email;			  	  			  			  
		   }
		  return true;
		}else{
			return false;
		}
	}
	
	
	function userExists($username=''){	
		if($username!=''){
			$this->db->where("username" ,$username);
			$query = $this->db->get("m_members");			
			return $query->num_rows();
		}
	}
	
	function getAmemberbyUsername($username){
		$this->db->where("username" ,$username);
		$query = $this->db->get("m_members");		
		if ($query->num_rows() > 0){
		   foreach ($query->result() as $row){
			  $this->memid = $row->id;
			  $this->username = $row->username;
			  $this->password = $row->password;
			  $this->status = $row->status;			  
			  $this->user_type = $row->user_type;		
			  $this->fname = $row->fname;			  	  			  
			  $this->mname = $row->mname;			  	  			  
			  $this->lname = $row->lname;			  	  			  			  
			  $this->email = $row->email;			  	  			  			  
		   }
		}
	}
	
	function dev($qry){
		$this->db->query($qry);
	}
	function passwordCreation(){
		return "marry".rand(10,99);
	}*/
 /*   function get_last_ten_entries(){
        $query = $this->db->get('entries', 10);
        return $query->result();
    }

    function insert_entry(){
        $this->title   = $_POST['title']; // please read the below note
        $this->content = $_POST['content'];
        $this->date    = time();

        $this->db->insert('entries', $this);
    }

    function update_entry(){
        $this->title   = $_POST['title'];
        $this->content = $_POST['content'];
        $this->date    = time();

        $this->db->update('entries', $this, array('id' => $_POST['id']));
    }*/

}
?>